Skip to content

API: Prohibit non-numeric dtypes in IntervalIndex #19022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 5, 2018

Conversation

jschendel
Copy link
Member

if isinstance(data, (list, tuple)) and len(data) == 0:
# GH 19016
# empty lists/tuples get object dtype by default, but this is not
# prohibited for IntervalIndex, so coerce to integer instead
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment here refers to the existing behavior of constructing an IntervalIndex from an empty list:

In [2]: pd.IntervalIndex([])
Out[2]:
IntervalIndex([]
              closed='right',
              dtype='interval[object]')

The changes in this PR caused this to raise, since the inferred subtype was object, which is now being disallowed. Changed this to be instead be integer by default. Don't have any strong reason for choosing integer, so can change.

@jreback
Copy link
Contributor

jreback commented Jan 1, 2018

rebase and push again, fixed some hanging by Travis CI

@jreback jreback added API Design Dtype Conversions Unexpected or buggy dtype conversions Interval Interval data type labels Jan 1, 2018
@codecov
Copy link

codecov bot commented Jan 2, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@c6166b0). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #19022   +/-   ##
=========================================
  Coverage          ?   91.53%           
=========================================
  Files             ?      148           
  Lines             ?    48814           
  Branches          ?        0           
=========================================
  Hits              ?    44683           
  Misses            ?     4131           
  Partials          ?        0
Flag Coverage Δ
#multiple 89.91% <100%> (?)
#single 41.57% <50%> (?)
Impacted Files Coverage Δ
pandas/core/indexes/interval.py 92.19% <100%> (ø)
pandas/core/dtypes/dtypes.py 95.31% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6166b0...cc22a03. Read the comment docs.

@@ -4,7 +4,7 @@
import numpy as np
from pandas import (
Interval, IntervalIndex, Index, isna, notna, interval_range, Timestamp,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe your test for .length should change? IIRC you were catching he exception

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.length had two tests: test_length and test_length_errors. I've removed test_length_errors in full, since we should be prohibiting dtypes that would cause exceptions. I've left test_length unchanged since it was only testing valid dtypes.

@@ -92,6 +94,18 @@ def _get_interval_closed_bounds(interval):
return left, right


def _maybe_convert_platform_interval(data):
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a doc-string, you can de-privatize (no leading _)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jreback jreback added this to the 0.23.0 milestone Jan 5, 2018
@jreback jreback merged commit 856c92b into pandas-dev:master Jan 5, 2018
@jreback
Copy link
Contributor

jreback commented Jan 5, 2018

thanks @jschendel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Dtype Conversions Unexpected or buggy dtype conversions Interval Interval data type
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: prohibit non-numeric dtypes in construction of IntervalIndex
2 participants